﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lidgren.Network;

namespace Network.Messages.LiveControl
{
    public class ResponseFullScreenshotMessage : NovaMessage
    {
        public Rectangle Region { get; set; }
        /// <summary>
        /// 所属区域
        /// </summary>
        public uint Number { get; set; }
        // So the receieving storage knows how many bytes to pre-allocate in advance
        //public int FinalLength { get; set; }

        public byte[] Image { get; set; }
        /// <summary>
        /// 帧计数
        /// </summary>
        public int SendFrameIndex { get; set; }

        public bool ReadComplete = false;
        public ResponseFullScreenshotMessage() : base((ushort)CustomMessageType.ResponseFullScreenshotMessage)
        {
        }

        public override void WritePayload(NetOutgoingMessage message)
        {
            base.WritePayload(message);
            message.Write(Region.X);
            message.Write(Region.Y);
            message.Write(Region.Width);
            message.Write(Region.Height);
            message.Write(Number);
            message.Write(Image.Length);
            message.Write(Image);
            message.Write(SendFrameIndex);
        }

        public override void ReadPayload(NetIncomingMessage message)
        {
            try
            {
                base.ReadPayload(message);
                Region = new Rectangle(message.ReadInt32(), message.ReadInt32(), message.ReadInt32(), message.ReadInt32());
                Number = message.ReadUInt32();
                Image = message.ReadBytes(message.ReadInt32());
                SendFrameIndex = message.ReadInt32();

                ReadComplete = true;
            }
            catch (Exception)
            {
                
                
            }
           
        }
    }
}
